package com.cwits.wifi.ui.dialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.cwits.wifi.R;


/**
 * Created by Administrator on 2016/1/19.
 */
public class ExpouseDialog extends PopupWindow {

    /**
     * type
     * <p/>
     * 1 分段录像时长
     * 2 自动关机
     * 3 屏幕保护
     * 4 白平衡
     * 5 重力感应
     * 6 光源Hz
     * 7 曝光补偿
     * 8 语言设置
     */


    private LinearLayout Ll_3, Ll_2, Ll_1, Ll0, Ll1, Ll2, Ll3;
    private TextView tv_3, tv_2, tv_1, tv0, tv1, tv2, tv3;
    private TextView tvTitle, tvType;
    private ImageView im_3, im_2, im_1, im0, im1, im2, im3;
    private View mMenuView;

    public ExpouseDialog(Activity context, View.OnClickListener itemsOnClick, View parent, int type, int size) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.dialog_expouse, null);
        Ll_3 = (LinearLayout) mMenuView.findViewById(R.id.dialog_expouse__3);
        Ll_2 = (LinearLayout) mMenuView.findViewById(R.id.dialog_expouse__2);
        Ll_1 = (LinearLayout) mMenuView.findViewById(R.id.dialog_expouse__1);
        Ll0 = (LinearLayout) mMenuView.findViewById(R.id.dialog_expouse_0);
        Ll1 = (LinearLayout) mMenuView.findViewById(R.id.dialog_expouse_1);
        Ll2 = (LinearLayout) mMenuView.findViewById(R.id.dialog_expouse_2);
        Ll3 = (LinearLayout) mMenuView.findViewById(R.id.dialog_expouse_3);

        im_3 = (ImageView) mMenuView.findViewById(R.id.dialog_expouse_im__3);
        im_2 = (ImageView) mMenuView.findViewById(R.id.dialog_expouse_im__2);
        im_1 = (ImageView) mMenuView.findViewById(R.id.dialog_expouse_im__1);
        im0 = (ImageView) mMenuView.findViewById(R.id.dialog_expouse_im_0);
        im1 = (ImageView) mMenuView.findViewById(R.id.dialog_expouse_im_1);
        im2 = (ImageView) mMenuView.findViewById(R.id.dialog_expouse_im_2);
        im3 = (ImageView) mMenuView.findViewById(R.id.dialog_expouse_im_3);

        tv_3 = (TextView) mMenuView.findViewById(R.id.dialog_expouse_tv__3);
        tv_2 = (TextView) mMenuView.findViewById(R.id.dialog_expouse_tv__2);
        tv_1 = (TextView) mMenuView.findViewById(R.id.dialog_expouse_tv__1);
        tv0 = (TextView) mMenuView.findViewById(R.id.dialog_expouse_tv_0);
        tv1 = (TextView) mMenuView.findViewById(R.id.dialog_expouse_tv_1);
        tv2 = (TextView) mMenuView.findViewById(R.id.dialog_expouse_tv_2);
        tv3 = (TextView) mMenuView.findViewById(R.id.dialog_expouse_tv_3);

        tvTitle = (TextView) mMenuView.findViewById(R.id.dialog_expouse_title);
        tvType = (TextView) mMenuView.findViewById(R.id.dialog_expouse_tv);

        //设置按钮监听
        Ll_3.setOnClickListener(itemsOnClick);
        Ll_2.setOnClickListener(itemsOnClick);
        Ll_1.setOnClickListener(itemsOnClick);
        Ll0.setOnClickListener(itemsOnClick);
        Ll1.setOnClickListener(itemsOnClick);
        Ll2.setOnClickListener(itemsOnClick);
        Ll3.setOnClickListener(itemsOnClick);

        switch (size) {
            case 0:
                im_3.setImageResource(R.mipmap.icon_select1);
                break;
            case 1:
                im_2.setImageResource(R.mipmap.icon_select1);
                break;
            case 2:
                im_1.setImageResource(R.mipmap.icon_select1);
                break;
            case 3:
                im0.setImageResource(R.mipmap.icon_select1);
                break;
            case 4:
                im1.setImageResource(R.mipmap.icon_select1);
                break;
            case 5:
                im2.setImageResource(R.mipmap.icon_select1);
                break;
            case 6:
                im3.setImageResource(R.mipmap.icon_select1);
                break;
        }

        switch (type) {
            case 1:  //分段录像时长

                tv_2.setText(context.getString(R.string.min_1));
                tv_1.setText(context.getString(R.string.min_2));
                tv0.setText(context.getString(R.string.min_3));
                Ll_3.setVisibility(View.GONE);
                Ll1.setVisibility(View.GONE);
                Ll2.setVisibility(View.GONE);
                Ll3.setVisibility(View.GONE);
                tvTitle.setText(context.getString(R.string.setting_time));
                break;
            case 2: //自动关机
                Ll_3.setVisibility(View.GONE);
                tv_3.setText(context.getString(R.string.setting_s0));
                tv_2.setText(context.getString(R.string.setting_s1));
                tv_1.setText(context.getString(R.string.setting_s2));
                tv0.setText(context.getString(R.string.setting_s3));
                Ll1.setVisibility(View.GONE);
                Ll2.setVisibility(View.GONE);
                Ll3.setVisibility(View.GONE);
                tvTitle.setText(context.getString(R.string.setting_close));
                break;
            case 3:  //屏幕保护
                tv_3.setText(context.getString(R.string.setting_s0));
                tv_2.setText(context.getString(R.string.setting_s3));
                tv_1.setText(context.getString(R.string.min_1));
                tv0.setText(context.getString(R.string.min_2));
                Ll1.setVisibility(View.GONE);
                Ll2.setVisibility(View.GONE);
                Ll3.setVisibility(View.GONE);
                tvTitle.setText(context.getString(R.string.setting_baohu));
                break;
            case 4:  //白平衡  自动、日光、阴天、钨丝灯、荧光灯
                tv_3.setText(context.getString(R.string.white_1));
                tv_2.setText(context.getString(R.string.white_2));
                tv_1.setText(context.getString(R.string.white_3));
                tv0.setText(context.getString(R.string.white_4));
                tv1.setText(context.getString(R.string.white_5));
                Ll2.setVisibility(View.GONE);
                Ll3.setVisibility(View.GONE);
                tvTitle.setText(context.getString(R.string.setting_bai));
                break;
            case 5: //重力感应  关、高、中、低
                tv_3.setText(context.getString(R.string.setting_s0));
                tv_2.setText(context.getString(R.string.normall_1));
                tv_1.setText(context.getString(R.string.normall_2));
                tv0.setText(context.getString(R.string.normall_3));
                Ll1.setVisibility(View.GONE);
                Ll2.setVisibility(View.GONE);
                Ll3.setVisibility(View.GONE);
                tvTitle.setText(context.getString(R.string.setting_zlgy));
                tvType.setVisibility(View.VISIBLE);
                break;
            case 6:  //光源Hz  50Hz、60Hz
                tv_3.setText("50Hz");
                tv_2.setText("60Hz");
                Ll_1.setVisibility(View.GONE);
                Ll0.setVisibility(View.GONE);
                Ll1.setVisibility(View.GONE);
                Ll2.setVisibility(View.GONE);
                Ll3.setVisibility(View.GONE);
                tvTitle.setText(context.getString(R.string.setting_gypl));
                break;
            case 7:
                //tv3.setVisibility(View.GONE);
                break;
            case 8:  //简体中文、繁体中文、English、Deutsch、日本语
                tv_3.setText(context.getString(R.string.language_cha));
                tv_2.setText(context.getString(R.string.language_chi));
                tv_1.setText(context.getString(R.string.language_eng));
                tv0.setText(context.getString(R.string.language_deu));
                tv1.setText(context.getString(R.string.language_jap));
                Ll2.setVisibility(View.GONE);
                Ll3.setVisibility(View.GONE);
                tvTitle.setText(context.getString(R.string.setting_yysz));
                break;
        }


        int h = context.getWindowManager().getDefaultDisplay().getHeight();
        int w = context.getWindowManager().getDefaultDisplay().getWidth();
        // 设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(false);
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        // 刷新状态
        this.update();
        this.showAtLocation(parent, Gravity.CENTER, 0, 0);

    }

}
